package indi.chengx.walty.ui.lisener;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

import javax.swing.JFrame;

import org.freedesktop.gstreamer.Pipeline;

import indi.chengx.walty.dirve.Camera;
import indi.chengx.walty.util.Console;

public class WindowListener implements WindowStateListener,KeyListener {
	private Camera camera;
	
	public WindowListener(Camera camera) {
		this.camera = camera;
	}
	
	public void windowStateChanged(WindowEvent e) {
		// TODO Auto-generated method stub
		switch(e.getNewState()) {
		case WindowEvent.WINDOW_CLOSING:
			Console.log("WindowListener", "cloase");
			camera.close();
			break;
		}
	}
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
	}
	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		if(e.getKeyCode() == KeyEvent.VK_SPACE) {
			camera.takePicture();
		}
	}
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
	}

}
